using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Globalization;
using ProgNetComponents.Data.SqlCe;
using System.Collections.Generic;
using MiniKsiegowosc.RaportTools;

namespace MiniKsiegowosc.Wrk.Ksiegi.KPIR
{
    public partial class raportKpir : MonthReportBase
    {
        public raportKpir()
        {
            InitializeComponent();
        }
       
        protected override string GetSelectString()
        {
            string SELECT = "select " +
                "W.WRK_KPIR_DATA AS DATA, " +
                "W.WRK_KPIR_NUMER_DOWODU_KSIEGOWEGO AS NUMER_DOWODU_KSIEGOWEGO, " +
                "K.STP_KON_NAZWA AS KONTRACHENT_NAZWA, " +
                "K.STP_KON_ADRES AS KONTRACHENT_ADRES, " +
                "W.WRK_KPIR_OPIS AS OPIS, " +
                "W.WRK_KPIR_UWAGI AS UWAGI, " +
                "COALESCE(SUM(K1.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_STIU, " +
                "COALESCE(SUM(K2.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_PP, " +
                "COALESCE(SUM(K3.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_ZT, " +
                "COALESCE(SUM(K4.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_KU, " +
                "COALESCE(SUM(K5.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_KR, " +
                "COALESCE(SUM(K6.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_WYN, " +
                "COALESCE(SUM(K7.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_PW, " +
                "COALESCE(SUM(K8.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_INNE " +
                "FROM WRK_KPIR W LEFT JOIN " +
                "STP_KONTRACHENCI K ON W.WRK_KPIR_KONTRACHENT = K.STP_KON_ID " +
                "LEFT JOIN WRK_KPIR_KWOTY K1 ON K1.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K1.WRK_KPIRK_TYP = 'STIU' " +
                "LEFT JOIN WRK_KPIR_KWOTY K2 ON K2.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K2.WRK_KPIRK_TYP = 'PP' " +
                "LEFT JOIN WRK_KPIR_KWOTY K3 ON K3.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K3.WRK_KPIRK_TYP = 'ZT' " +
                "LEFT JOIN WRK_KPIR_KWOTY K4 ON K4.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K4.WRK_KPIRK_TYP = 'KU' " +
                "LEFT JOIN WRK_KPIR_KWOTY K5 ON K5.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K5.WRK_KPIRK_TYP = 'KR' " +
                "LEFT JOIN WRK_KPIR_KWOTY K6 ON K6.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K6.WRK_KPIRK_TYP = 'WYN' " +
                "LEFT JOIN WRK_KPIR_KWOTY K7 ON K7.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K7.WRK_KPIRK_TYP = 'PW' " +
                "LEFT JOIN WRK_KPIR_KWOTY K8 ON K8.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K8.WRK_KPIRK_TYP = 'INNE' " +
                "WHERE DATEPART(YEAR, W.WRK_KPIR_DATA) = " + Rok + " AND DATEPART(MONTH, W.WRK_KPIR_DATA) = " + Miesiac + " " +
                "GROUP BY  " +
                "W.WRK_KPIR_DATA , " +
                "W.WRK_KPIR_NUMER_DOWODU_KSIEGOWEGO , " +
                "K.STP_KON_NAZWA , " +
                "K.STP_KON_ADRES , " +
                "W.WRK_KPIR_OPIS, " +
                "W.WRK_KPIR_UWAGI  ";
            return SELECT;
        }
        
    }
}
